﻿Public Class TMyEvents
    Inherits TCustomMyObjects

    Friend Sub New(ByVal AOwner As TMyDatabase)
        MyBase.New(AOwner)
    End Sub

    Public Overrides Sub Refresh()
        _List.Clear()
        MyQuery.Clear()
        MyQuery.SQL.AppendLine("select")
        MyQuery.SQL.AppendLine(" event_catalog")
        MyQuery.SQL.AppendLine(",event_schema")
        MyQuery.SQL.AppendLine(",event_name")
        MyQuery.SQL.AppendLine(",definer")
        MyQuery.SQL.AppendLine(",time_zone")
        MyQuery.SQL.AppendLine(",event_body")
        MyQuery.SQL.AppendLine(",event_definition")
        MyQuery.SQL.AppendLine(",event_type")
        MyQuery.SQL.AppendLine(",execute_at")
        MyQuery.SQL.AppendLine(",interval_value")
        MyQuery.SQL.AppendLine(",interval_field")
        MyQuery.SQL.AppendLine(",sql_mode")
        MyQuery.SQL.AppendLine(",starts")
        MyQuery.SQL.AppendLine(",ends")
        MyQuery.SQL.AppendLine(",status")
        MyQuery.SQL.AppendLine(",on_completion")
        MyQuery.SQL.AppendLine(",created")
        MyQuery.SQL.AppendLine(",last_altered")
        MyQuery.SQL.AppendLine(",last_executed")
        MyQuery.SQL.AppendLine(",event_comment")
        MyQuery.SQL.AppendLine(",originator")
        MyQuery.SQL.AppendLine(",character_set_client")
        MyQuery.SQL.AppendLine(",collation_connection")
        MyQuery.SQL.AppendLine(",database_collation")
        MyQuery.SQL.AppendLine("from")
        MyQuery.SQL.AppendLine(" information_schema.events")
        MyQuery.SQL.AppendLine("where")
        MyQuery.SQL.AppendLine("event_schema=?event_schema")
        MyQuery.SQL.AppendLine("order by")
        MyQuery.SQL.AppendLine(" event_schema")
        MyQuery.SQL.AppendLine(",event_name")
        MyQuery.DeclareAndSet("event_schema", Me.DatabaseName)
        MyQuery.Execute()
        While Not MyQuery.Eof
            Dim item As New TMyEvent(Me, MyQuery.FieldAsString("event_name"))
            item._EventCatalog = MyQuery.FieldAsString("event_catalog")
            item._EventSchema = MyQuery.FieldAsString("event_schema")
            item._EventName = MyQuery.FieldAsString("event_name")
            item._Definer = MyQuery.FieldAsString("definer")
            item._TimeZone = MyQuery.FieldAsString("time_zone")
            item._EventBody = MyQuery.FieldAsString("event_body")
            item._EventDefinition = MyQuery.FieldAsString("event_definition")
            item._EventType = MyQuery.FieldAsString("event_type")
            item._ExecuteAt = MyQuery.FieldAsDateTime("execute_at")
            item._IntervalValue = MyQuery.FieldAsString("interval_value")
            item._IntervalField = MyQuery.FieldAsString("interval_field")
            item._SqlMode = MyQuery.FieldAsString("sql_mode")
            item._Starts = MyQuery.FieldAsDateTime("starts")
            item._Ends = MyQuery.FieldAsDateTime("ends")
            item._Status = MyQuery.FieldAsString("status")
            item._OnCompletion = MyQuery.FieldAsString("on_completion")
            item._Created = MyQuery.FieldAsDateTime("created")
            item._LastAltered = MyQuery.FieldAsDateTime("last_altered")
            item._LastExecuted = MyQuery.FieldAsDateTime("last_executed")
            item._EventComment = MyQuery.FieldAsString("event_comment")
            item._Originator = MyQuery.FieldAsInteger("originator")
            item._CharacterSetClient = MyQuery.FieldAsString("character_set_client")
            item._CollationConnection = MyQuery.FieldAsString("collation_connection")
            item._DatabaseCollation = MyQuery.FieldAsString("database_collation")
            _List.Add(item)
            MyQuery.MoveNext()
        End While
        MyQuery.Close()
    End Sub
End Class
